package com.jerry.lastgomall.order.controller;

import com.alipay.api.AlipayApiException;
import com.jerry.lastgomall.order.service.OrderService;
import com.jerry.lastgomall.order.util.AlipayTemplate;
import com.jerry.lastgomall.order.vo.PayVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@RequestMapping("pay/pay")
@Controller
public class PayWebController {

    @Autowired
    private AlipayTemplate alipayTemplate;
    @Autowired
    private OrderService orderService;
    /**
     * 去支付
     */
    @ResponseBody
    @GetMapping("/payOrder")
    public String payOrder(@RequestParam("orderId") String orderId) throws AlipayApiException {
        //订单信息
        PayVo payVo= orderService.getOrderPay(orderId);
        System.out.println("订单信息"+payVo);
        String pay = alipayTemplate.pay(payVo);
        System.out.println(pay);
        return "hello";
    }
}
